SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[SP_TCMOBA_DETR_D01]
/*---------------------------------------------------------*/
/*---Empresa              : OFISIS S.A.                  --*/
/*---Cliente              : OFISIS S.A.                  --*/
/*---Sistema              : Tesoreria                    --*/
/*---M÷dulo               : Empresa                      --*/
/*---Programa             : eXTORM. datos Detraccion	 --*/
/*---                     TMDOCU_PROV y a la  TCMOBA_DETR--*/
/*---Nombre SP            : SP_TCMOBA_DETR_D01           --*/
/*---Desarrollado por     : Carlos Marquez E.            --*/
/*---Fecha Creaci÷n       : 13/12/2006                   --*/
/*---Base Datos           : Microsoft Sql Server         --*/
/*---Versi÷n              : 8.0                          --*/
/*---Invoca a SP          :                              --*/
/*---------------------------------------------------------*/
/*---------------------------------------------------------*/
/*---Modificado 1 por     : 				 			--*/
/*---Fecha Modificaciön   : 				 			--*/
/*---Detalle Modificaciön : 				 			--*/
/*---------------------------------------------------------*/
/*-------------------------------------------------------*/  
/*---Modificado 2 por     : 				 			--*/
/*---Fecha Modificaciön   : 				 			--*/
/*---Detalle Modificaciön : 				 			--*/
/*---------------------------------------------------------*/
/*---------------------------------------------------------*/      
/*---Modificado 3 por     : 				 			--*/
/*---Fecha Modificaciön   : 				 			--*/
/*---Detalle Modificaciön : 				 			--*/
/*---------------------------------------------------------*/
/*---------------------------------------------------------*/
/*---Comentarios                                        --*/
/*---                                                   --*/
/*---                                                   --*/
/*---------------------------------------------------------*/
/*---------------------------------------------------------*/
/*---	Drop Proc SP_TCMOBA_DETR_D01                    --*/
/*---	Grant Execute on SP_TCMOBA_DETR_D01 to public   --*/
/*---	Set NoCount On
Declare
 @ISCO_EMPR			TD_VC_002,   
 @ISCO_USUA_MODI	TD_VC_008,  
 @ISCO_BANC			TD_VC_003,   
 @ISNU_CNTA_BANC	TD_VC_020,  
 @ISAA_BNCO			TD_VC_004,   
 @ISMM_BNCO			TD_VC_002,   
 @ISTI_MOVI_BANC	TD_VC_001,    
 @ISNU_COMP_BANC	TD_VC_008

Set	@ISCO_EMPR = '01'
Set	@ISCO_USUA_MODI = 'OFISIS'
Set	@ISCO_BANC = 'INT'		
Set	@ISNU_CNTA_BANC = '100-3000-183580'
Set	@ISAA_BNCO = '2006'
Set	@ISMM_BNCO = '10'
Set	@ISTI_MOVI_BANC = 'E'
Set	@ISNU_COMP_BANC = '00300344' ---'00300034' -- 

Execute SP_TCMOBA_DETR_D01 @ISCO_EMPR, @ISCO_USUA_MODI, @ISCO_BANC, @ISNU_CNTA_BANC, @ISAA_BNCO, @ISMM_BNCO, @ISTI_MOVI_BANC, 
@ISNU_COMP_BANC

							   */
/*---------------------------------------------------------*/
 @ISCO_EMPR			TD_VC_002,   
 @ISCO_USUA_MODI	TD_VC_008,  
 @ISCO_BANC			TD_VC_003,   
 @ISNU_CNTA_BANC	TD_VC_020,  
 @ISAA_BNCO			TD_VC_004,   
 @ISMM_BNCO			TD_VC_002,   
 @ISTI_MOVI_BANC	TD_VC_001,    
 @ISNU_COMP_BANC	TD_VC_008

As    
Declare
/* Variables  */      
@VSST_PROC		TD_VC_001


Begin Tran SP_TCMOBA_DETR_D01

	Update TMDOCU_PROV set TMDOCU_PROV.NU_DEPO_DETR =  Null, TMDOCU_PROV.FE_DEPO_DETR = Null

	From	TCMOBA_DETR
	 Inner Join TMPARA_TESO On
	(	TCMOBA_DETR.CO_EMPR = TMPARA_TESO.CO_EMPR)
	 Inner Join TDMOVI_BANC On
	(	TCMOBA_DETR.CO_EMPR = TDMOVI_BANC.CO_EMPR And
		TCMOBA_DETR.CO_UNID_CONC = TDMOVI_BANC.CO_UNID_CONC And
		TCMOBA_DETR.CO_BANC = TDMOVI_BANC.CO_BANC And
		TCMOBA_DETR.NU_CNTA_BANC = TDMOVI_BANC.NU_CNTA_BANC And
		TCMOBA_DETR.AA_BNCO = TDMOVI_BANC.AA_BNCO And
		TCMOBA_DETR.MM_BNCO = TDMOVI_BANC.MM_BNCO And
		TCMOBA_DETR.TI_MOVI_BANC = TDMOVI_BANC.TI_MOVI_BANC And
		TCMOBA_DETR.NU_COMP_BANC = TDMOVI_BANC.NU_COMP_BANC )

	Inner Join TMDOCU_PROV On
	(	TDMOVI_BANC.CO_EMPR = TMDOCU_PROV.CO_EMPR And
		TDMOVI_BANC.TI_ENTI = TMPARA_TESO.CO_TIAU_PROV And
		TDMOVI_BANC.CO_ENTI = TMDOCU_PROV.CO_PROV And
		TDMOVI_BANC.TI_DOCU_ENTI = TMDOCU_PROV.CO_TIPO_DOCU And
		TDMOVI_BANC.NU_DOCU_ENTI = TMDOCU_PROV.NU_DOCU_PROV )

	Where
	TCMOBA_DETR.CO_EMPR = @ISCO_EMPR And
	TCMOBA_DETR.CO_BANC = @ISCO_BANC And
	TCMOBA_DETR.NU_CNTA_BANC = @ISNU_CNTA_BANC And
	TCMOBA_DETR.AA_BNCO = @ISAA_BNCO And
	TCMOBA_DETR.MM_BNCO = @ISMM_BNCO And
	TCMOBA_DETR.TI_MOVI_BANC = @ISTI_MOVI_BANC And
	TCMOBA_DETR.NU_COMP_BANC = @ISNU_COMP_BANC 
	If (@@ERROR != 0)   
	Begin    
		Raiserror 20001 'ERROR DE INSERCION'    
		RollBack Tran SP_TCMOBA_DETR_D01
		Return    
	End         
	


	Delete	TDMOBA_DETR
	Where	CO_EMPR = @ISCO_EMPR
		And CO_BANC = @ISCO_BANC
		And NU_CNTA_BANC = @ISNU_CNTA_BANC
		And AA_BNCO = @ISAA_BNCO
		And MM_BNCO = @ISMM_BNCO
		And TI_MOVI_BANC = 'E'
		And NU_COMP_BANC = @ISNU_COMP_BANC

	If (@@ERROR != 0)   
	Begin    
		Raiserror 20001 'ERROR DE INSERCION'    
		RollBack Tran SP_TCMOBA_DETR_D01
		Return    
	End         


	Delete	TCMOBA_DETR
	Where	CO_EMPR = @ISCO_EMPR
		And CO_BANC = @ISCO_BANC
		And NU_CNTA_BANC = @ISNU_CNTA_BANC
		And AA_BNCO = @ISAA_BNCO
		And MM_BNCO = @ISMM_BNCO
		And TI_MOVI_BANC = 'E'
		And NU_COMP_BANC = @ISNU_COMP_BANC

	If (@@ERROR != 0)   
	Begin    
		Raiserror 20001 'ERROR DE INSERCION'    
		RollBack Tran SP_TCMOBA_DETR_D01
		Return    
	End         

Commit Tran SP_TCMOBA_DETR_D01
/*--------------------------- Fin -------------------------------- */


GO
